package com.loong.common.rabbitmq.dto.base;

import com.loong.common.rabbitmq.enums.CommonEvent;
import lombok.*;

import java.io.Serializable;

/**
 * @Description: 订单上报通用事件
 * @Author: hzp
 * @Date: 2021-1-2 12:11
 */
@Setter
@Getter
@Builder
@ToString
@AllArgsConstructor
public class CommonEventDto<T> implements Serializable {
    /**
     * @see CommonEvent
     */
    private Short eventCode;
    private T data;

    public  static <T> CommonEventDto<T> buildWithCreate(T data){
        return CommonEventDto.<T>builder().eventCode(CommonEvent.CREATE.getCode()).data(data).build();
    }
    public static <T> CommonEventDto<T> buildWithDelete(T data){
        return CommonEventDto.<T>builder().eventCode(CommonEvent.DELETE.getCode()).data(data).build();
    }
    public static <T> CommonEventDto<T> buildWithUpdate(T data){
        return CommonEventDto.<T>builder().eventCode(CommonEvent.UPDATE.getCode()).data(data).build();
    }
    public   CommonEventDto(){

    }
    public static class CommonEventDtoBuilder<T>{
        private CommonEventDto.CommonEventDtoBuilder<T> builder(){
            return new CommonEventDto.CommonEventDtoBuilder<T>();
        }
    }
}
